<?php
/**
 * Created by PhpStorm.
 * User: 夏浩文
 * Date: 2017/6/14
 * Time: 15:01
 */
namespace app\hongyanche\controller;

class forum
{
    private $auth;
    public function __construct()
    {
        model('product')->demand('forum');
        if (!model('admin')->is('forum')['state']) {
            $res = array('state' => 0, 'errormsg' => 'authority incorrect', 'errorcode' => '');
            $this->auth = $res;
        }else{
            $this->auth = array('state'=>1);
        }
    }
    //模板列表
    public function label_list()
    {
        $newpost = input('newpost');
        $res = model('forum')->label_list($newpost);
        return json($res);
    }
    //发布帖子
    public function add()
    {
        $filter['title'] = input('title');
        $filter['content'] = input('content');
        $filter['label_id'] = input('label_id');
        $filter['tag'] = input('tag');
        $res = model('forum')->add($filter);
        return json($res);
    }
//    //修改帖子
//    public function modify()
//    {
//        $product_brand_id = input('forum_id');
//        $key = input('key');
//        $content = input('content');
//        $res = model('product')->modify($product_brand_id, $key, $content);
//        return json($res);
//    }
    //删除帖子
    public function remove()
    {
        $brand_id = input('forum_id');
        $res = model('forum')->remove($brand_id);
        return json($res);
    }
    //修改帖子
    public function modify()
    {
        $id = input('forum_id');
        $filter['title'] = input('title');
        $filter['content'] = input('content');
        $filter['label_id'] = input('label_id');
        $filter['tag'] = input('tag');
        $res = model('forum')->modify($id,$filter);
        return json($res);
    }

    //帖子列表
    public function forum_list()
    {
        $filer['page'] = input('page');
        $filer['type'] = input('type');
        $filer['label_id'] = input('label_id');
        $filer['mine'] = input('mine');
        $res = model('forum')->forum_list($filer);
        return json($res);
    }
    //开放、关闭
    public function release()
    {
        if (!empty($this->auth) && !$this->auth['state']) return json($this->auth);
        $brand_id = input('forum_id');
        $release = input('release');
        $res = model('product')->release($brand_id, $release);
        return json($res);
    }
    //回帖
    public function reply()
    {
        $data['forum_id'] = input('forum_id');
        $data['content'] = input('content');
        $data['pid'] = input('pid');
        $data['url'] = input('url');
        $res = model('forum')->reply($data);
        return json($res);
    }
    //删除回复
    public function reply_remove()
    {
        $reply_id = input('reply_id');
        $res = model('forum')->reply_remove($reply_id);
        return json($res);
    }
    //用户回复列表
    public function reply_list()
    {
        $res = model('forum')->reply_list();
        return json($res);
    }
    //点赞
    public function fabulous()
    {
        $data['forum_id'] = input('forum_id');
        $res = model('forum')->fabulous($data);
        return json($res);
    }
    //根据id获取详情
    public function getinfo()
    {
        $forum_id = input('forum_id');
        $pages = input('page');
        $res = model('forum')->getInfo($forum_id,$pages);
        return json($res);
    }
    //签到
    public function sign()
    {
        return json(model('forum')->sign());
    }

    //版主邀请确认
    public function moderator_confirm()
    {
        $label_id = input('label_id');
        $res = model('forum')->moderator_confirm($label_id);
        return json($res);
    }

    //加精
    public function highlight()
    {
        $forum_id = input('forum_id');
        $highlight = input('highlight');
        $res = model('forum')->highlight($forum_id,$highlight);
        return json($res);
    }
    //置顶
    public function top()
    {
        $forum_id = input('forum_id');
        $top = input('top');
        $res = model('forum')->top($forum_id,$top);
        return json($res);
    }
    //审核
    public function apply_dispose()
    {
        $forum_id = input('forum_id');
        $approve = input('approve');
        $reason = input('reason');
        $label_id = input('label_id');
        $res = model('forum')->apply_dispose($forum_id,$approve,$reason,$label_id);
        return json($res);
    }

    //用户信息
    public function getUserInfo()
    {
        $user_id = input('user_id');
        $res = model('forum')->getUserInfo($user_id);
        return json($res);
    }
    //根据user_id获取用户帖子列表
    public function getlistbyuserd()
    {
        $user_id = input('user_id');
        $data['reply'] = input('reply');
        $data['apply'] = input('apply');
        $data['fail'] = input('fail');
        $page = input('page');
        $res = model('forum')->getlistbyuserd($user_id,$data,$page);
        return json($res);
    }
    //获取重卡汇表情
    public function getExpression()
    {
        return json(model('forum')->getExpression());
    }
}
